local sk__wuwei = fk.CreateSkill {

  name = "sk__wuwei",

  tags = {  },

}


sk__wuwei:addEffect(fk.EventPhaseStart, {
  name = "sk__wuwei",
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(sk__wuwei.name) and player.phase == Player.Draw
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getNCards(3)
    room:moveCardTo(cards, Card.Processing, nil, fk.ReasonJustMove, sk__wuwei.name, nil, true, player)
    room:delay(800)
    local obtain, basic_cards = {}, {}
    for _, id in ipairs(cards) do
      if Fk:getCardById(id).type == Card.TypeBasic then
        table.insert(basic_cards, id)
      else
        table.insert(obtain, id)
      end
    end
    if #basic_cards > 0 then
      room:moveCardTo(basic_cards, Card.DiscardPile, nil, fk.ReasonJustMove, sk__wuwei.name, nil, true, player)
    end
    if #obtain > 0 then
      room:moveCardTo(obtain, Card.PlayerHand, player, fk.ReasonJustMove, sk__wuwei.name, nil, true, player)
    end
    room:delay(800)
    if not player.dead and #basic_cards > 0 then
      for i = 1, #basic_cards, 1 do
        if player.dead or not player:canUse(Fk:cloneCard("slash")) then return end
        local use=room:askToUseVirtualCard(player,{
          name = "slash",
          subcards = {},
          skill_name = sk__wuwei.name,
          prompt = "#sk__wuwei-invoke",
          cancelable = true,
          skip = true,
          extra_data = {
            bypass_times = false,
            bypass_distance = true,
          },
        })
        if use then
          room:useCard(use)
        else
          break
        end
      end
    end
    return true
  end,
})

return sk__wuwei